package com.mldong.modules.sys.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.mldong.sse.SseService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * <p>
 * SSE
 * </p>
 *
 * @author mldong
 * @since 2025-04-27
 */
@RestController
@Api(tags = "SSE管理")
@RequiredArgsConstructor
public class SseController {
    private final SseService sseService;
    @PostMapping(value = "/sse/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter getSse() {
        return sseService.addEmitter(StpUtil.getTokenInfo().getTokenValue());
    }

}
